/**
 * 
 */
package com.ztesoft.web.baseconfig.service;

import java.util.List;

import com.ztesoft.core.common.Page;
import com.ztesoft.framework.exception.BaseAppException;
import com.ztesoft.web.baseconfig.db.po.ColumnNamePO;
import com.ztesoft.web.baseconfig.db.po.ColumnsRelationPO;
import com.ztesoft.web.baseconfig.db.po.DmSrcTablePO;
import com.ztesoft.web.baseconfig.db.po.DmStrategyPO;
import com.ztesoft.web.baseconfig.db.po.DmTargetTablePO;
import com.ztesoft.web.baseconfig.db.po.TargetTablePO;

/**
 * <Description> <br>
 * 
 * @author codeCreater<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2014年11月11日 <br>
 * @since V1.0<br>
 * @see com.ztesoft.web.baseconfig.service <br>
 */

public interface IDmTargetTableService {

	/**
	 * 根据策略ID获取改策略下的所有目标表数据
	 * 
	 * @param po
	 * @return
	 * @throws BaseAppException
	 */
	List<DmTargetTablePO> selectByDmStrategyId(DmStrategyPO po) throws BaseAppException;

	/**
	 * 根据表名查找
	 * 
	 * @param record
	 * @return
	 * @throws BaseAppException
	 */
	List<DmTargetTablePO> selectByTableName(DmTargetTablePO record) throws BaseAppException;

	/**
	 * 根据表名，在本地已经配置好的数据库中，查找
	 * 
	 * @param record
	 * @return
	 * @throws BaseAppException
	 */
	List<DmTargetTablePO> selectByTableNameForShow(DmSrcTablePO record) throws BaseAppException;

	/**
	 * 根据计划ID，查询出该计划下的所有目标表
	 * 
	 * @param dmPlanId
	 * @return
	 * @throws BaseAppException
	 */
	List<DmTargetTablePO> selectByDmPlanId(Integer dmPlanId) throws BaseAppException;

	DmTargetTablePO selectByPrimaryKey(Integer key) throws BaseAppException;

	List<DmTargetTablePO> selectByArg(DmTargetTablePO record) throws BaseAppException;

	Page<DmTargetTablePO> selectByArgAndPage(DmTargetTablePO record, Page<DmTargetTablePO> resultPage)
			throws BaseAppException;

	DmTargetTablePO add(DmTargetTablePO record) throws BaseAppException;

	/**
	 * 保存目标数据相关信息，包括，分表定义，字段映射
	 * 
	 * @param record
	 * @param state
	 *            :00A、0DA、00D
	 * @return
	 * @throws BaseAppException
	 * @throws Exception
	 */
	List<TargetTablePO> addWithOther(DmTargetTablePO record, String state) throws BaseAppException, Exception;

	/**
	 * 目标表验证按钮，验证目标表是否存在，并配置字段映射
	 * 
	 * @param dstPO
	 *            , dttPO
	 * @return
	 * @throws BaseAppException
	 */
	DmTargetTablePO stColumnsRelation(DmTargetTablePO dttPO) throws BaseAppException;

	int addForDraft(DmTargetTablePO record, String state) throws BaseAppException;

	int update(DmTargetTablePO record) throws BaseAppException;

	int delete(DmTargetTablePO record) throws BaseAppException;

	/**
	 * 验证表名是否存在，返回字段
	 * 
	 * @param record
	 *            :查询内容， isSubTable：是否是分表，hasSubTable：是否有分表（查询按钮 or 验证）
	 * @return
	 * @throws BaseAppException
	 */
	ColumnNamePO[] selectTableName(DmSrcTablePO record, boolean isSubTable, boolean hasSubTable)
			throws BaseAppException;

	/**
	 * 获取源表和目标表的字段映射信息
	 * 
	 * @param srcColumnList
	 * @param targetColumnList
	 * @return
	 * @throws BaseAppException
	 */
	List<ColumnsRelationPO> getColumnsRelationList(List<ColumnNamePO> srcColumnList, List<ColumnNamePO> targetColumnList)
			throws BaseAppException;

	DmTargetTablePO selectBySourceId(Integer sourceDataId)throws BaseAppException;

}
